package cn.com.zero.sample.trade.customer.controller;

import cn.com.zero.db.vo.PageVO;
import cn.com.zero.sample.trade.api.po.OrderPO;
import cn.com.zero.sample.trade.api.service.IOrderService;
import cn.com.zero.sample.trade.customer.po.User;
import cn.com.zero.sample.trade.customer.service.IPaymentService;
import cn.com.zero.web.util.PageRequestUtil;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liuxh
 * @version 1.0.0
 * @Description 委托接口
 * @createTime 2022/7/13 16:11
 */
@RestController
public class OrderController {

    @Autowired
    private IPaymentService paymentService;

    @Autowired(required = false)
    @DubboReference
    private IOrderService orderService;


    /**
     * 下委托
     *
     * @param orderPO 订单对象
     */
    @PostMapping("/consumer/payment/create")
    public int order(OrderPO orderPO) {
        return orderService.order(orderPO);
    }

    /**
     * 获取委托
     *
     * @param id 订单ID
     */
    @GetMapping("/consumer/payment/get/{id}")
    public OrderPO getPayment(@PathVariable("id") Long id) {
        return paymentService.getPaymentById(id);
    }


    /**
     * 获取委托列表
     */
    @GetMapping("/consumer/payment/list")
    PageVO<OrderPO> getList() {
        // 访问 http://localhost:8001/consumer/payment/list?pageNum=1&pageSize=4&orderBy=id desc
        return PageRequestUtil.getPageInfo(() -> paymentService.getPaymentList());
    }


    //-----------------------------------------dubbo---------

    /**
     * 获取委托列表
     */
    @GetMapping("/consumer/payment/rpc/list")
    PageVO<OrderPO> getRPCList() {
        return orderService.getPaymentRPCList(PageRequestUtil.getPageParams());
    }

    //------------------------------------------------------------


    @PostMapping("/consumer/user/create")
    public void create(@RequestBody User user) throws Exception {
        paymentService.createUser(user);
    }

}
